package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StatsVo;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.util.RedisKeys;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
//暂时关闭持久化
//@Component
public class RedisDataPersistenceJob {

    @Reference
    private IStrategyStatisVOService strategyStatisVOService;

    @Reference
  private   IStrategyDetailService strategyDetailService;

    //定时器
    @Scheduled(cron = "0/10 * * * * ?")
    public void doWord(){
        System.out.println("-------------vo持久化-------------------");

        List<StrategyStatisVO> vos=
        strategyStatisVOService.listVo(RedisKeys.STRATGY_STATS_VO.join("*"));

        for (StrategyStatisVO vo : vos) {

            StatsVo statsVo = new StatsVo();
            BeanUtils.copyProperties(vo,statsVo);
            //update 到数据库
            strategyDetailService.updateStatisVo(statsVo);
        }
        System.out.println("-------------vo持久化结束-------------------");

    }

}
